package com.itheima.health.service.impl;

import com.itheima.health.dao.*;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.MobileSetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * C端
 */
@Service
public class MobileSetMealServiceImpl implements MobileSetMealService {


    @Autowired
    private SetMealDao setMealDao;

    @Autowired
    private CheckGroupDao checkGroupDao;

    @Autowired
    private CheckItemDao checkItemDao;

    @Autowired
    private SetmealCheckgroupDao setmealCheckgroupDao;

    @Autowired
    private CheckgroupCheckitemDao checkgroupCheckitemDao;

    @Autowired
    private MobileSetMealDao mobileSetMealDao;


    /**
     * C端_体检预约_套餐详情查看
     */
    @Override
    public Setmeal findById(Integer id) {
        List<CheckGroup> checkGroups = new ArrayList();
        //根据套餐Id查询检查组的Id集合
        Integer [] checkGroupList=setmealCheckgroupDao.findById(id);

        for (Integer checkGroup : checkGroupList) {
            //根据遍历出的Id查询出检查组
            CheckGroup checkGroup1 = checkGroupDao.getById(checkGroup);

            //根据检查组id查询检查项id的集合
            Integer [] checkItems =checkgroupCheckitemDao.getCheckItemByIds(checkGroup1.getId());

            //根据检查项的ID集合查询出检查项
            List<CheckItem> checkItemList=checkItemDao.getById(checkItems);

            checkGroup1.setCheckItems(checkItemList);
            checkGroups.add(checkGroup1);
        }
            //将查询出的数据组装
        //Setmeal setmeal = new Setmeal();
        //根据id查询套餐
        Setmeal setmeal1=setMealDao.findById(id);
        setmeal1.setCheckGroups(checkGroups);

        return setmeal1;

    }

    /**
     * c端-套餐展示
     * @return
     */
    @Override
    public List<Setmeal> findAll() {
        return mobileSetMealDao.findAll();
    }
}
